#include<stdio.h>
#include<stdlib.h>
#include<time.h>

/*c语言中级学习第10课：数组之随机打乱*/

int main()
{
    int arr[5] = {1,2,3,4,5};
    int len = sizeof(arr) / sizeof(arr[0]);
 
    srand(time(NULL));
    for (int i = 0; i < len; i++)
    {
        int index = rand() % len;//获得范围为0~4的随机数

        int temp = arr[i];
        arr[i] = arr[index];
        arr[index] = temp;
    }

    for (int i = 0; i < len; i++)
    {
        printf("%d ",arr[i]);
    }

    return 0;
}